//
//  CPHeadFooter.m
//  ChinaPoem
//
//  Created by 赵俊明 on 2019/3/6.
//  Copyright © 2019 赵俊明. All rights reserved.
//

#import "CPHeadFooter.h"
@interface CPHeadFooter()
@property (nonatomic, weak) UILabel *name;
@property (nonatomic, weak) UIButton *moreBtn;
@end
@implementation CPHeadFooter
+ (instancetype)cp_headTableView:(UITableView *)tableView
{
    static NSString *headID = @"header";
    CPHeadFooter *headView  = [tableView dequeueReusableHeaderFooterViewWithIdentifier:headID];
    if (headView == nil) {
        headView = [[CPHeadFooter alloc] initWithReuseIdentifier:headID];
        headView.contentView.backgroundColor = JMColor(240, 240, 240);
    }
    
    return headView;
}

// 重用headView
- (id)initWithReuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithReuseIdentifier:reuseIdentifier]) {
        UILabel *name = [[UILabel alloc] initWithFrame:CGRectZero];
        name.font = [UIFont systemFontOfSize:20];
        name.textColor = JMColor(139, 139, 139);
        [self.contentView addSubview:name];
        name.textAlignment = NSTextAlignmentLeft;
        self.name = name;
        
        UIButton *moreBtn = [UIButton buttonWithType:(UIButtonTypeSystem)];
        [moreBtn addTarget:self action:@selector(moreAction:) forControlEvents:(UIControlEventTouchUpInside)];
        [moreBtn setImage:[UIImage imageNamed:@"back"] forState:(UIControlStateNormal)];
        moreBtn.tintColor = [UIColor grayColor];
        [self.contentView addSubview:moreBtn];
        self.moreBtn = moreBtn;
    }
    return self;
}

- (void)moreAction:(UIButton *)sender
{
    if (self.cp_moreAction) {self.cp_moreAction(_groups);}
}

- (void)setGroups:(NSString *)groups
{
    _groups = groups;
    self.name.text = [NSString stringWithFormat:@"%@", groups];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    CGFloat x = 10;
    CGFloat y = 0;
    CGFloat w = self.contentView.bounds.size.width;
    _name.frame = CGRectMake(x, y, w*0.5, self.height);
    _moreBtn.frame = CGRectMake(self.width-40, 4, 30, 30);
}

@end

#pragma mark - **************** CPHistoryModel
@implementation CPHistoryModel
@end
